<!DOCTYPE html>
<html>
<head>
<base href="${basePath}">
<meta charset="UTF-8">
<title>修改产品</title> $!{include("import_js_css.html")}
<!-- #set(Product product) -->
<script>
	function documentReady() {
		var msg = '${msg}';
		if (msg == 'xpf') {
			var xpf = alert("修改产品失败!");
			setTimeout(function() {
				xpf.close().remove();
			}, 1000);
		}
		
		$("#selProductType").select2({
			width: "100%",
			minimumResultsForSearch: -1
		});
	}
</script>
</head>
<body>
	$!{include("header.html")}
	<div class="menu_all">
		<div class="div_search_result clear">
			<div class="panel-heading panel-result-title">
				<h3 class="panel-title">修改产品</h3>
			</div>
			<div class="panel-form-add">
				<form class="form-horizontal" role="form" action="yueyogaAdmin/addProduct.jhtml" method="POST">
					<input type="hidden" name="productId" value="${product.productId}" />
					<div class="panel-form-layout">
						<label for="txtProductName" class="col-sm-1 control-label">产品名称</label>
						<div class="col-sm-3">
							<input type="text" required class="form-control" name="name" id="txtProductName" value="${product.name}">
						</div>
						<label for="inputMemberLevel" class="col-sm-1 control-label">产品类型</label>
						<div class="col-sm-3">
							<select class="selectpicker show-menu-arrow" readOnly data-width="100%" name="type" id="selProductType">
								<option value="101">按次卡</option>
								<option value="102">按时间</option>
								<option value="107">按金额</option>
								<option value="103">年卡</option>
								<option value="104">季卡</option>
								<option value="105">月卡</option>
								<option value="106">半月卡</option>
								<option value="108">实时扣费</option>
							</select>
						</div>
						<br /> <br /> <label for="txtPrice" class="col-sm-1 control-label">产品价格</label>
						<div class="col-sm-3">
							<input type="text" class="form-control" onkeyup="clearNoNumOfAlert(this)" name="price" id="txtPrice" required value="${product.price}">
						</div>
						<div id="div_counts">
							<label for="txtProductCounts" class="col-sm-1 control-label">产品次数</label>
							<div class="col-sm-3">
								<input type="text" class="form-control" name="counts" onkeydown="this.value=this.value.replace(/\D/g,'')"
										onafterpaste="this.value=this.value.replace(/\D/g,'')"  id="txtProductCounts" value="${product.counts}" >
							</div>
						</div>
						<br /> <br /> <label for="txtPrice" class="col-sm-1 control-label">每周限制</label>
						<div class="col-sm-3">
							<select class="selectpicker" data-width="100%" name="limitOfWeek" id="limitOfWeek">
								<option value="">不限制</option>
								<option value="1">1次</option>
								<option value="2">2次</option>
								<option value="3">3次</option>
								<option value="4">4次</option>
								<option value="5">5次</option>
								<option value="6">6次</option>
								<option value="7">7次</option>
								<option value="8">8次</option>
								<option value="9">9次</option>
								<option value="10">10次</option>
							</select>
						</div>
						
						<br /> <br /> <label for="txtRemarks" class="col-sm-1 control-label">产品备注</label>
						<div class="col-sm-3">
							<textarea class="form-control panel-form-address" name="remarks" id="txtRemarks" >${product.remarks}</textarea>
						</div>
						<br /> <br /> <br /> <br />
						<div id="div_datetime" class="panel-space" style="display: none;">
							<label for="txt_time_begin" class="col-sm-1 control-label">起始日期</label>
							<div class="col-sm-3">
								<div id="inputBirthday" class="input-group date form_datetime">
									<input name="beginTime" id="txt_time_begin" class="form-control" size="16" type="text" value="${product.beginTime}" readonly> <span class="input-group-addon"><span
										class="glyphicon glyphicon-remove"></span></span> <span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>
								</div>
							</div>
							<label for="txt_time_end" class="col-sm-1 control-label">截止日期</label>
							<div class="col-sm-3">
								<div id="inputBirthday" class="input-group date form_datetime">
									<input id="txt_time_end" name="endTime" class="form-control" size="16" type="text" value="${product.endTime}" readonly> <span class="input-group-addon"> <span
										class="glyphicon glyphicon-remove"></span></span><span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>
								</div>
							</div>
						</div>
						<div class="clear panel-btn-search">
							<button type="submit" class="btn-ade-default panel-mr">保存</button>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
	$(function() {
		var proType = "${product.type}";
		if (proType) {
			$("#selProductType").val(proType);
			showOrHidDiv(proType);
		}
		$("#selProductType").change(function() {
			var type = $(this).val();
			type = type * 1;
			showOrHidDiv(type);
		});
		
		var limitWeek = "${product.limitOfWeek}";
		if(limitWeek){
			$("#limitOfWeek").val(limitWeek);
		}
		
		var msg = '${msg}';
		if (msg != null && msg != '') {
			alert(msg);
			return;
		}
	});
	function showOrHidDiv(type) {
		if (type == 101) {
			$("#div_datetime").hide();
			$("#div_counts").show();
		} else if (type == 102) {
			$("#div_counts").hide();
			$("#div_datetime").show();
		} else if (type > 102) {
			$("#div_counts").hide();
			$("#div_datetime").hide();
		}
	}
	function clearNoNumOfAlert(obj){

	    //得到第一个字符是否为负号
	    var t = obj.value.charAt(0);  
	       //先把非数字的都替换掉，除了数字和.   
	       obj.value = obj.value.replace(/[^\d.]/g,"");   
	       //必须保证第一个为数字而不是.   
	       obj.value = obj.value.replace(/^\./g,"");   
	       //保证只有出现一个.而没有多个.   
	       obj.value = obj.value.replace(/\.{2,}/g,".");   
	       //保证.只出现一次，而不能出现两次以上   
	       obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
	       //如果第一位是负号，则允许添加
	       if(t == '-'){
	         obj.value = '-'+obj.value;
	       }
	}
</script>
</html>
